package info.touret.winecellar.bottle.client;

import com.google.gwt.user.client.ui.ListBox;

import java.util.Arrays;
import java.util.List;

/**
 * Centralise la creation des notes
 * 
 * @author touret-a
 * 
 */
public class NotesFactory {
	private static NotesFactory factory;

	private final String[] NOTES = new String[] { "0", "1", "2", "3", "4", "5",
			"6", "7", "8", "9", "10" };

	protected NotesFactory() {
	}

	/**
	 * Retourne le singleton
	 * 
	 * @return
	 */
	public static NotesFactory getFactory() {
		if (factory == null) {
			setFactory(new NotesFactory());
		}
		return factory;
	}

	private static void setFactory(NotesFactory factory) {
		NotesFactory.factory = factory;
	}

	private List<String> notes;

	/**
	 * @return la liste des notes
	 */
	public List<String> getNotes() {
		if (notes == null) {
			setNotes(Arrays.asList(NOTES));
		}

		return notes;
	}

	private void setNotes(List<String> notes) {
		this.notes = notes;
	}

	/**
	 * Assigne les notes par defaut dans un listbox
	 * 
	 * @param _listbox
	 *            la liste a remplir
	 */
	public void makeNotes(ListBox _listbox) {
		for (String i : NOTES) {
			_listbox.addItem(String.valueOf(i), String.valueOf(i));
		}
	}

}
